<!--
 * @Author: XieQiu 雪球
 * @Date: 2021-05-10 15:07:49
 * @LastEditTime: 2023-07-10 10:58:03
 * @LastEditors: Please set LastEditors
 * @Description: 人员奖惩积分页面 字段未改
-->
<template>
  <BaseMainSlot :show-tab="false" :show-btn-box="false">
    <!-- <template v-slot:zhactbar>
      <ActionBar
        :add-active="addActive"
        :del-active="delActive"
        :edit-active="editActive"
        :has-cancel="false"
        :has-save="false"
        :save-active="saveActive"
        @add="add"
        @cancel="cancel('formData')"
        @edit="edit"
        @del="del"
        @save="save('formData')"
      />
    </template>-->
    <template v-slot:search-box>
      <SearchForm :formConfig="formConfig" :formData="searchlist" @search="search"></SearchForm>
    </template>
    <template v-slot:table-box>
      <el-table
        ref="tableData"
        v-loading="loading"
        highlight-current-row
        :data="tableData"
        stripe
        border
        height="88%"
        @row-click="handleEdit"
        @selection-change="handleSelectionChange"
      >
        <!-- <el-table-column type="selection" width="55" /> -->
        <el-table-column type="index" label="序号" width="50" />
        <el-table-column prop="personName" label="人员名称" />
        <el-table-column prop="originalIntegral" label="原积分" />
        <el-table-column prop="fractionChange" label="积分明细">
          <template v-if="scope.row.personnelRewardList" slot-scope="scope">
            <span>{{ scope.row.fractionChange }} 分</span>
            <!-- <span v-if="!scope.row.fractionChange"> —— </span> -->
          </template>
        </el-table-column>
        <el-table-column prop="integralRecord" label="现积分">
          <template v-if="scope.row.personnelRewardList" slot-scope="scope">
            <span v-if="scope.row.currentIntegral">{{ scope.row.currentIntegral }} 分</span>
            <span v-if="!scope.row.currentIntegral">——</span>
          </template>
        </el-table-column>
        <el-table-column prop="personnelRewardList" label="历史积分">
          <template v-if="scope.row.personnelRewardList" slot-scope="scope">
            <el-button type="text" @click.stop="dialogReward(scope.row.personNo)">积分明细</el-button>
          </template>
        </el-table-column>
      </el-table>
      <Pagination
        :page-size="pageSize"
        :current-page="currentPage"
        :total-size="totalSize"
        @changePageSize="changePageSize"
        @changeCurrentPage="changeCurrentPage"
      />
      <el-dialog
        title="积分明细"
        :visible.sync="dialogCategoryVisible"
        width="30%"
        :before-close="handleClose"
      >
        <el-table
          ref="tableData"
          v-loading="loading"
          highlight-current-row
          :data="dialogRewardData"
          stripe
          border
          height="88%"
          @row-click="handleEdit"
          @selection-change="handleSelectionChange"
        >
          <!-- <el-table-column type="selection" width="55" /> -->
          <el-table-column type="index" label="序号" width="50" />
          <el-table-column prop="personnelName" label="人员名称" />
          <el-table-column prop="category" label="奖惩信息类别" />
          <el-table-column prop="integralDetail" label="具体内容" />
          <!-- <el-table-column prop="originalIntegral" label="原积分" /> -->
          <el-table-column prop="score" label="积分明细">
            <template v-if="scope.row.personnelName" slot-scope="scope">
              <span v-if="scope.row.integralDetail">{{ scope.row.integralDetail }} 分</span>
              <span v-if="!scope.row.integralDetail">——</span>
            </template>
          </el-table-column>
          <!-- <el-table-column prop="integralRecord" label="现积分">
            <template v-if="scope.row.personnelName" slot-scope="scope">
              <span v-if="scope.row.currentIntegral">{{ scope.row.currentIntegral }} 分</span>
              <span v-if="!scope.row.currentIntegral"> —— </span>
            </template>
          </el-table-column>-->
          <el-table-column prop="rewardTime" :formatter="dateFormat" label="奖惩时间" />
        </el-table>
      </el-dialog>
    </template>
  </BaseMainSlot>
</template>

<script>
// import ActionBar from "@/components/ActionBar";
import SearchForm from '@/components/searchForm';
import Pagination from "@/components/Pagination";
import BaseMainSlot from "@/components/BaseMainSlot/newBaseMainSlot";
// import StaffManage from "@/api/digital-operation/personnel-cost-mansge/staff-manage/index";
import PersonnelRewardPoints from "@/api/digital-operation/personnel-cost-mansge/personnel-reward-points/index";
import { mymixin } from "@/utils/mixins";
export default {
  name: "PersonnelRewardPoints",
  components: { SearchForm, Pagination, BaseMainSlot },
  mixins: [mymixin],
  data() {
    return {
      formConfig: [
        {
          label: '人员名称',
          prop: 'personNo',
          type: 'select',
          options: [], // StaffData
          optionKey: { label: 'personName', value: 'personNo' },
        },
      ],
      searchlist: {},
      polyedit: false,
      // 承租户
      personNo: "",
      StaffData: [],
      dialogRewardData: [],
      dialogCategoryVisible: false
    };
  },
  watch: {},
  created() {
    // 获取表格数据
    this.getTableDataList();
  },
  mounted() {
    this.getBaseList();
  },
  methods: {
    // 获取表格数据
    getTableDataList() {
      this.formData = {};
      this.loading = true;
      let params = {
        page: this.currentPage,
        size: this.pageSize,
        sort: "timestamp",
        entity: {
          personNo: this.searchlist.personNo
        }
      };
      PersonnelRewardPoints.getPersonIntegralRewardList(params).then(res => {
        this.loading = false;
        let data = res.data;
        if (data) {
          this.totalSize = data.totalElements;
          // this.tableData = [];
          this.tableData = data.content;
          this.addblankmet();
          // console.log(this.tableData)
          this.resetActionBar();
        }
      });
    },
    async getBaseList() {
      // 员工
      const {
        data: Staff
      } = await PersonnelRewardPoints.getStaffListByCondition();
      this.StaffData = Staff;
      let list = Staff.map(el => {
        return { personName: el.person.name, personNo: el.person.personNo }
      })
      this.setOptions(this.formConfig, 'personNo', list)
    },
    async dialogReward(row) {
      // console.log(row)
      if (row) {
        const { data: res } = await PersonnelRewardPoints.getByCondition({
          personNo: row,
          organizationNo: sessionStorage.organizationNo
        });
        this.dialogRewardData = [];
        this.dialogRewardData = res;
        console.log(this.dialogRewardData);
        // this.dialogRewardData = JSON.parse(JSON.stringify(row))
        this.$nextTick(() => {
          this.dialogCategoryVisible = true;
        });
      }
    },
    // 转换时间格式
    dateFormat(row, colnum) {
      if (row.rewardTime) {
        return this.$moment(row[colnum.property]).format("YYYY-MM-DD HH:mm:ss");
      }
    },
    handleClose(done) {
      // this.$confirm("确认关闭？")
      //   .then(_ => {
      done();
      //   })
      //   .catch(_ => {});
    },
    // 初始化操作栏状态
    resetActionBar() {
      // this.$refs["formData"].resetFields();
      this.$refs["tableData"].clearSelection();
      this.canInput = false;
      this.addActive = true;
      this.delActive = false;
      this.saveActive = false;
      this.cancelActive = false;
      this.editActive = false;
    },
    // 搜索
    search() {
      this.currentPage = 1;
      this.getTableDataList();
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.getTableDataList();
    },
    changeCurrentPage(currentPage) {
      this.currentPage = currentPage;
      this.getTableDataList();
    },
    // 点击行时
    handleEdit(row) {
      // TODO 点击行元素后 edit
      // this.queryFaciliy();
      this.formData = JSON.parse(JSON.stringify(row));
      this.editActive = true;
      this.saveActive = false;
      this.cancelActive = false;
      this.canInput = false;
      this.qrActive = true;
    },
    handleSelectionChange(list) {
      this.facilityIdList = [];
      this.facilityIdList = list.map(item => item.facilityId);
      this.delActive = this.facilityIdList.length > 0;
    }
  }
};
</script>

<style scoped lang="scss">
@import "~@/styles/variables.scss";

// 弹出框  统一样式
::v-deep .el-dialog__wrapper {
  // background-color: rgba(124, 143, 143, 0);
  .el-dialog {
    background-color: rgba(240, 243, 247, 1);
    // width: 55% !important;

    // width: 55% !important;
    min-width: 55%;
    border: #000 1px solid;
    border-radius: 9px;
    overflow: hidden;
    color: #000;
    .el-dialog__header {
      width: 100%;
      background-color: rgba(0, 110, 145, 1);
      padding: 15px;
      .el-dialog__title {
        font-weight: 700;
      }
      .el-dialog__close {
        font-size: 22px;
        color: #fff;
        font-weight: 700;
      }
    }
    .el-dialog__body {
      overflow: hidden;
      // overflow-y: auto;
      .el-input__inner {
        color: #000;
        border-color: rgba(217, 217, 217, 1);
        background-color: rgba(255, 255, 255, 1);
      }
      .el-textarea__inner {
        color: #000;
        border-color: rgba(217, 217, 217, 1);
        background-color: rgba(255, 255, 255, 1);
      }
      width: 100%;
      margin-bottom: 10px;
      .el-table {
        max-height: 200px;
        overflow-y: auto;
        background-color: rgba(255, 255, 255, 1);
        .cell {
          color: #000;
        }
        th {
          background-color: rgba(230, 230, 230, 1);
        }
        th.is-leaf {
          border-color: rgba(77, 77, 77, 1);
        }
        td {
          border-color: rgba(77, 77, 77, 1);
        }
        tr:hover {
          background-color: rgba(77, 77, 77, 1);
        }
        .el-table__empty-text {
          color: #000;
        }
        .current-row {
          // background-color: rgb(177, 177, 177);
          background-color: #dbdbdb !important;
        }
        .el-table__row--striped {
          background-color: rgba(255, 255, 255, 1);
        }
        // color: #000;
      }
      .el-table--border {
        border-color: rgba(77, 77, 77, 1);
        border-top-left-radius: 8px;
        border-top-right-radius: 8px;
      }
      .el-table--enable-row-hover .el-table__body tr:hover > td {
        background-color: rgb(177, 177, 177);
      }
      .el-table__body tr.current-row > td {
        background-color: #dbdbdb !important;
      }
      // .el-button {
      //   width: 100%;
      // }
      .el-form {
        // width: 100%;
        // margin: ;
        .el-form-item {
          margin-bottom: 0 !important;
        }
        .el-form-item__content {
          display: flex;
          width: 100%;
          .el-select {
            min-width: 15%;
          }
          .el-input {
            min-width: 10%;
          }
          .el-input__inner {
            border-right: none;
          }
          .el-button {
            min-width: 5%;
            margin-left: 10px;
          }
        }
      }
      .el-form-item {
        display: flex;
        .el-form-item__label {
          line-height: 36px;
          min-width: 120px;
          text-align: end;
        }
        .el-form-item__content {
          line-height: 36px;
          width: 100%;
          display: flex;
        }
      }
    }
    .el-dialog__footer {
      width: 100%;
      border-top: 1px solid rgba(191, 191, 191, 1);
      position: inherit;
      text-align: right;
      padding: 15px;
    }
    .el-form-item__label {
      color: #000;
      font-weight: 400;
      font-size: 16px;
    }
  }
}
</style>
